import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;

@WebServlet("/ShowRequest")
public class ShowRequestMethod extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html");
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(req.getProtocol());
        stringBuffer.append("<br>");
        stringBuffer.append(req.getMethod());
        stringBuffer.append("<br>");
        stringBuffer.append(req.getRequestURI());
        stringBuffer.append("<br>");
        stringBuffer.append(req.getContextPath());
        stringBuffer.append("<br>");
        stringBuffer.append(req.getQueryString());
        stringBuffer.append("<br>");

        Enumeration<String> headerNames = req.getHeaderNames();
        while (headerNames.hasMoreElements()){
            String headerName = headerNames.nextElement();
            stringBuffer.append(headerName + ":" + req.getHeader(headerName));
            stringBuffer.append("<br>");
        }
        
        resp.getWriter().write(stringBuffer.toString());
    }

}
